/*
 * @Author: Binggan
 * @Date: 2020-01-13 15:40:55
 * @LastEditors  : Binggan
 * @LastEditTime : 2020-01-13 16:11:12
 * @Description: 工具函数
 */
import {Notice} from 'iview';

//全屏
function fullScreen(){
    var el = document.documentElement || document.body;
    var rfs = el.requestFullscreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullscreen;

    //typeof rfs != "undefined" && rfs
    if (typeof rfs != "undefined" && rfs) {
        rfs.call(el);
    }
    else if (typeof window.ActiveXObject !== "undefined") {
        //for IE，这里其实就是模拟了按下键盘的F11，使浏览器全屏
        //注：ie调用ActiveX控件，需要在ie浏览器安全设置里面把 ‘未标记为可安全执行脚本的ActiveX控件初始化并执行脚本' 设置为启用
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript != null) {
            wscript.SendKeys("{F11}");
        }
    }
}

//退出全屏
function exitScreen(){
    var el = document;
    var cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen ||el.msExitFullscreen;

    //typeof cfs != "undefined" && cfs
    if (cfs) {
        cfs.call(el);
    }
    else if (typeof window.ActiveXObject !== "undefined") {
        //for IE，这里和fullScreen相同，模拟按下F11键退出全屏
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript != null) {
            wscript.SendKeys("{F11}");
        }
    }
}

function lowBrowserTip(){
    Notice.error({
        title: '系统运行提示',
        desc: '为保证本系统正常运行，请使用IE11或Chrome（谷歌浏览器）、360浏览器、QQ浏览器等主流浏览器打开！',
        duration: 10
    });
}
function getBrowserV(){
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if(isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var IEVersion = parseFloat(RegExp["$1"]);
        if(IEVersion<11 || !navigator.userAgent.match(/x64/i)){//兼容IE9(64位)+
            lowBrowserTip();
        }
    }
    // lowBrowserTip();
}

export default {
    getBrowserV,
    fullScreen,
    exitScreen
}